package com.zhizuobiao.controller;

import com.zhizuobiao.entity.Items;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 实现处理器
 */
public class HelloController implements Controller {

    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {

        List<Items> itemsList = new ArrayList<Items>();

        Items items_1 = new Items();
        items_1.setName("联想笔记本");
        items_1.setPrice(6000f);
        items_1.setDetail("ThinkPad T430 联想笔记本电脑！");

        Items items_2 = new Items();
        items_2.setName("苹果手机");
        items_2.setPrice(5000f);
        items_2.setDetail("iphone6苹果手机！");

        itemsList.add(items_1);
        itemsList.add(items_2);


        // 模型视图对象
        ModelAndView mv = new ModelAndView();

        // 设置视图
        // /WEB-INF/hello.jsp 视图名称
//        mv.setViewName("/WEB-INF/jsp/hello.jsp");
        // 有视图解析器，可以简写为
        mv.setViewName("hello"); // 自动添加前缀和后缀
        // 设置数据
        mv.addObject("itemsList", itemsList);

        return mv;
    }

}
